<template>
	<view class="contain">
		<view class="padding-tb25">
			<view class="padding-10">
				<view class="flex f-j-c f-a-c ">
					<text class="t-color-9">{{i18n['订单号']}}：{{orderNo}}</text>
				</view>
				<view class="flex f-j-c f-a-c f44-size text-price margin-t12">{{amount}}</view>
			</view>
		</view>
		<view class="padding-lr20">
			<pay-item ref="payitem"></pay-item>
			<view class="padding-lr10">
				<view class="padding-15"></view>
				<button
					:disabled="btnLoading"
					:loading="btnLoading"
					@click="pay" class="flex f-a-c f-j-c b-radius-5 bg-color-linear-y f15-size t-color-w h-40">{{i18n['确认支付']}}
				</button>
			</view>
			<!-- <button
				class="confirm-btn"
				:class="'bg-' + themeColor.name"
				:disabled="btnLoading"
				:loading="btnLoading"
				@tap="confirm"
			>
				确认支付
			</button> -->
		</view>
	</view>
</template>
<style scoped>
	@import url('../../static/css/page/white.css');
	@import url('../../static/css/iconcolor.css');
</style>
<script>
	import payItem from '@/components/common/payitem';
	const API = require('@/utils/api/order.js').default;
	const $ = require('@/utils/api.js');
	let self;
	export default {
		data() {
			return {
					btnLoading: false,
				orderNo: '',
				amount: 0,
				payTypeList: {
					order_ali_pay:"1",
					order_balance_pay: "1",
					order_wechat_pay: "1",
				},
			};
		},
		onLoad: function(options) {
			self = this;
			self.orderNo = options.orderNo ? options.orderNo : '';
			self.amount = options.amount ? options.amount : '';
			this.init();
			$.setTitle(self.i18n['收银台']);
		},
		methods: {
			getDetail() {
				$.ajax({
					url: API.orderDetailApi,
					data: {
						orderId: self.id
					},
					method: 'GET',
					success(res) {
						let info = res.data ? res.data : '';
						if(info == ''){return}
						self.goodsList = info.orderDetailList ? info.orderDetailList : [];
						self.groupJoinList = info.groupMemberList ? info.groupMemberList : [];
						self.order = info.order ? info.order : '';
						self.group = info.orderGroup ? info.orderGroup : '';
						self.shopMemberId = info.shopMemberId ? info.shopMemberId : '';
						self.now = res.now;
						if(self.order.finishExpiredTime) {//自动确认收货时间
							self.autoGetGoods = Number(self.order.finishExpiredTime - res.now)/1000;
						}
						if(self.order.payEndTime) {//超过这个时间未支付订单取消
							self.cancelTime = Number(self.order.payEndTime - res.now)/1000;
						}


						console.log("self.goodsList",self.goodsList)
						self.goodsList.forEach(function(item, index, array) {

							// item 是arr1数组中的每一项
							// index 是arr1数组的索引值，Number类型
						      item.qrcode =self.markCode(item.verifyCode);
						})
						// self.goodsList.forEach(function(item, index, array) {
						// 	// 这个函数内的this指向arr2
						// 	// item 是arr1数组中的每一项
						// 	// index 是arr1数组的索引值，Number类型
						// }, arr2)





					}
				})
			},
			async pay() {



				if (this.payTypeList.order_ali_pay === '0' && this.payTypeList.order_wechat_pay === '0') return;


				this.btnLoading = true;
				setTimeout(() => {
					this.btnLoading = false;
				}, 2 * 1000);

				// const params = {};
				// params.money = parseFloat(this.inputAmount);
				// this.btnLoading = true;
				// const route = `/money/success?type=${this.type}&id=${this.marketingId}&order_id=${this.orderInfo['order_id']}`;
				// setTimeout(() => {
				// 	this.btnLoading = false;
				// }, 0.5 * 1000);


				let  order_group = "order"
				let  params  = {
					orderNo: self.orderNo,
					payMethod: self.$refs.payitem.type
				}


				// switch (parseInt(this.payType, 10)) {
				switch (self.$refs.payitem.type) {
					case 'wxPay': // 微信支付
						await this.$mPayment.weixinPay(order_group,  {	orderNo: self.orderNo,payMethod: self.$refs.payitem.type}, '/pages//order/suc', this.code);
						break;
					case 'aliPay': // 支付宝支付
						await this.$mPayment.aliPay(order_group, {	orderNo: self.orderNo,payMethod: self.$refs.payitem.type}, '/pages/order/suc');
						break;
					case "balance":
						await this.$mPayment.balancePay(order_group, {	orderNo: self.orderNo,payMethod: self.$refs.payitem.type}, '/pages/order/suc');
						break;
					default:
						break;
				}
			},



			// pay() {
			// 	$.ajax({
			// 		url: API.payOrderApi,
			// 		data: {
			// 			payOrderNo: self.orderNo,
			// 			payMethod: self.$refs.payitem.type
			// 		},
			// 		method: 'POST',
			// 		success(res) {

			// 			console.log(res)
			// 				console.log("self.$refs.payitem.type",self.$refs.payitem.type)
			// 			if (self.$refs.payitem.type == 'wxPay') {
			// 					// #ifndef H5
			// 					console.log("111")
			// 					$.wxPay({
			// 						payType: self.$refs.payitem.type.toLocaleLowerCase(),
			// 						data: res.data,
			// 						success(res) {
			// 							self.go('/pages/order/suc', 2);
			// 						}
			// 					})
			// 					// #endif



			// 					// #ifdef H5
			// 					$.wxPayH5({
			// 						data: res.data,
			// 						success(res) {
			// 							self.go('/pages/order/suc', 2);
			// 						}
			// 					})
			// 					// #endif
			// 			}
	  //                   if (self.$refs.payitem.type  == 'aliPay') {

			// 				$.wxPay({
			// 					payType: self.$refs.payitem.type.toLocaleLowerCase(),
			// 					data: res.data.message,
			// 					success(res) {
			// 						self.go('/pages/order/suc', 2);
			// 					}
			// 				})

			// 			}
			// 			if (self.$refs.payitem.type == 'balance') {
			// 				self.go('/pages/order/suc', 2);
			// 			}
			// 		}
			// 	})
			// },

			init() {},
		},
		created() {},
		computed: {
			i18n() {
				return this.$t('pay')
			},
		},
		mounted() {},
		destroyed() {},
		components: {
			payItem
		},
		onPullDownRefresh() {},
		onReachBottom() {}
	}
</script>
